package com.mojito.gorm.executor.impl;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;

/**
 * @author mojito
 */
public class ParamHandler {
    /**
     * 参数填充进预编译语句
     *
     * @param statement
     * @param params
     */
    public void prepareValue(PreparedStatement statement, Object[] params) throws SQLException {
        if (params == null || params.length == 0) {
            return;
        }
        int index = -1;
        for (int i = 0; i < params.length; i++) {
            index = i + 1;
            if (params[i] instanceof Integer) {
                statement.setInt(index, (Integer) params[i]);
            }
            if (params[i] instanceof Long) {
                statement.setLong(index, (Long) params[i]);
            }
            if (params[i] instanceof Boolean) {
                statement.setBoolean(index, (Boolean) params[i]);
            }
            if (params[i] instanceof String) {
                statement.setString(index, String.valueOf(params[i]));
            }
        }
    }
}
